package com.testxmlparse;

import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.builder.BaseBuilder;
import org.apache.ibatis.builder.SqlSourceBuilder;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.ResultMap;
import org.apache.ibatis.mapping.ResultMapping;
import org.apache.ibatis.mapping.MappedStatement.Builder;
import org.apache.ibatis.mapping.SqlCommandType;
import org.apache.ibatis.mapping.SqlSource;
import org.apache.ibatis.session.Configuration;

import cn.com.zte.ngbc.base.expression.enhance.OgnlCompiler;
import cn.com.zte.ngbc.busi.cm.servicetype.ceti.CeNbKccl;
import cn.com.zte.ngbc.busi.cmtran.transdef.ceti.Ce5101;
import cn.com.zte.ngbc.dao.CursorHandler;
import cn.com.zte.ngbc.dao.mybatis.JdbcCodeGenerator;
import cn.com.zte.ngbc.dao.mybatis.JdbcCodeGenerator.SqlQuery;
import cn.com.zte.ngbc.frw.model.ModelObjectCreator;
import org.apache.ibatis.executor.result.DefaultResultContext;
public class Testa {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		  
       Configuration configuration = new Configuration();
       SqlSourceBuilder builder1 = new SqlSourceBuilder(configuration);  
       SqlSource sqlSource =builder1.parse("select  * from ac01;", Integer.class, (Map<String, Object>) new HashMap<>().put("aa", "bb")); 
		Builder builder = new MappedStatement.Builder(configuration, "abc", sqlSource, SqlCommandType.INSERT);  
		List<ResultMap> resultMaps=new ArrayList<>();
		ResultMap.Builder inlineResultMapBuilder = new ResultMap.Builder(
                configuration,
                "sss" + "-Inline",
                Object.class,
                new ArrayList<ResultMapping>(),
                null);
        resultMaps.add(inlineResultMapBuilder.build());
        builder.resultMaps(resultMaps);
		MappedStatement ms=   builder.build();
	System.out.println(ms.getResultMaps().get(0));	
String  code=	JdbcCodeGenerator.generateSqlQueryCode(ms);
		System.out.println(code);
		  OgnlCompiler c = new OgnlCompiler();
		  try {
			  SqlQuery ret=	c.genOneMethodClass(SqlQuery.class, "aa",code, "query", new Class[] { Connection.class, Object.class, CursorHandler.class, Integer.TYPE, Integer.TYPE });
		      ret.toString();
		  
		  } catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
//		  c.getClass();
//	c.genOneMethodClass(null, 
//			"a", 
//			"select  * from ac01",
//			"query",
//			new Class[] { Connection.class, Object.class, CursorHandler.class, Integer.TYPE, Integer.TYPE }
//	);
		
//		CeNbKccl.CeCkService.Input a=	ModelObjectCreator.get().create(CeNbKccl.CeCkService.Input.class);
//	a.setZhaiyodm("asdfasdf");
//	    System.out.println(a);
//		Map ab=new HashMap<>();
//		ab.put("corpCode", "");
//		SysBusLog abc=	new SysBusLog();
//		abc.setCorpCode("sdfsdf");
//		try {
//		String a=	BeanUtils.getProperty(ab, "corpCode");
//	System.out.println(StringUtils.isEmpty(a));	
//		System.out.println(a);
//		} catch (Exception e) {
//			e.printStackTrace();
//		} 
		List a=new ArrayList<>();
		
		for (int i = 0; i < 50; i++) {
			a.add(i);
		}
	  	name(a,new CursorHandler<Object>(){
	  		@Override
	  		public boolean handle(int paramInt, Object paramT) {
	  			// TODO Auto-generated method stub
	  			System.out.println(paramInt);
	  			if(paramInt%2==0){
	  				return true;
	  			}
	  			return false;
	  		}
	  		
	  	} );
	  	System.out.println("大小"+a.size());
		
	
	}
	
	
	private static void name(List a,CursorHandler b) {
		for (int i = a.size()-1; i >=0 ; i--) {
			if(!b.handle(i, a.get(i))){
				a.remove(i);
			}
		}
			
		}
		
		
	
	

}
